/*
 *  TerminalLibrary.c
 *  AutoEllips
 *
 *  Created by Simon Martin on 01/06/2010.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */

#include "TerminalLibrary.h"

void getDoubleValue(WINDOW *wind,const char* name,double *val,double min,double max)
// routine to get valid value from user  - value must be in range min<=val<=max
{
	char* valueString;
	valueString=(char *)malloc(50*sizeof(char)); // local storage for input
	double valueDouble;
	int loop=1;
	//prompt for new value
	while (loop) {
		
		mvprintw(20,0,"Input new value for %s (Minimum:%g, maximum: %g):",name,min,max);
		refresh();
		echo();
		//read in new value
		scanw("%s",valueString);
		valueDouble=atof(valueString);
		//test to see if value is in valid range. if so accept and return. otherwise prompt user again
		if ((valueDouble>=min)&&(valueDouble<=max)) {
			*val=valueDouble;
			loop=0;
		}
		
		
	}
	noecho();
	return;
}